using System.Drawing;
using System.IO;
using NMock2;


namespace NMockExtensions
{
    public class EqualImageMatcher : Matcher
    {
        private readonly Bitmap expected;

        public EqualImageMatcher(Bitmap expected)
        {
            this.expected = expected;
        }

        public override bool Matches(object obj)
        {
            Bitmap actual = obj as Bitmap;
            if (actual == null)
            {
                return false;
            }
            if (expected.Width != actual.Width) return false;
            if (expected.Height != actual.Height) return false;

            for (int x = 0; x < actual.Width; ++x)
            {
                for (int y = 0; y < actual.Height; ++y)
                    if (expected.GetPixel(x, y) != actual.GetPixel(x, y)) return false;
            }
            return true;
        }

        public override void DescribeTo(TextWriter writer)
        {
            writer.Write("Equal Bitmap");
        }
    }
}